package com.whfc.ms.api.base.controller;

import com.whfc.base.entity.AppSchedule;
import com.whfc.common.result.R;
import com.whfc.common.util.SessionAttr;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.base.service.ScheduleService;
import org.junit.Assert;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 日程表(AppSchedule)表控制层
 *
 * @author makejava
 * @since 2022-08-01 11:59:23
 */
@RestController
@RequestMapping("/ms/api/appSchedule")
public class AppScheduleController {
    /**
     * 服务对象
     */
    @Resource
    private ScheduleService appScheduleService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<AppSchedule> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.appScheduleService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param appSchedule 实体
     * @return 新增结果
     */
    @PostMapping
    public R add(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @RequestBody AppSchedule appSchedule) {
        this.appScheduleService.insert(user,appSchedule);
        return R.success();
    }

    /**
     * 编辑数据
     *
     * @param appSchedule 实体
     * @return 编辑结果
     */
    @PostMapping("edit")
    public R edit(@RequestBody AppSchedule appSchedule) {
        this.appScheduleService.update(appSchedule);
        return R.success();
    }

    /**
     * 删除数据
     *
     * @return 删除是否成功
     */
    @PostMapping("delete")
    public R<Boolean> deleteById(@RequestBody AppSchedule appSchedule) {
        Integer id = appSchedule.getId();
        Assert.assertNotNull(id);
        boolean b = this.appScheduleService.deleteById(id);
        if(b){
            return  R.success();
        }else{
            return R.failure();
        }

    }

}

